import React, { Component } from 'react'
import { StyleSheet, View } from 'react-native'

import { connect } from 'react-redux'
import HeaderDefault from '../../components/header/HeaderDefault'
import { theme_app } from '../../utils/appTheme'
import ScrollableTabView from 'react-native-scrollable-tab-view'
import TabelePage1 from './Page1'
import { getPatientOfMyWard } from '../../netServer/signs_net'

import Toast from 'react-native-simple-toast'

class SignsBatch extends Component {
  constructor(props) {
    super(props)
    this.state = { patientList: [], patientList1: [] }
  }
  static navigationOptions = ({ navigation }) => ({
    gesturesEnabled: false,
    header: (
      <HeaderDefault backBtnOnPress={navigation.goBack} title="批量录入" />
    )
  })

  componentDidMount() {
    this._loadPatinetListWithUserName()
  }

  _loadPatinetListWithUserName = () => {
    let paramss = new FormData()
    paramss.append('userName', this.props.user_info.user_name)
    getPatientOfMyWard(paramss, resp => {
      let { code, data = [], msg } = resp

      if (code == '0') {
        this.setState({
          patientList: data,
          patientList1: data
        })
      } else {
        Toast.showWithGravity(msg, 0.3, Toast.CENTER)
      }
    })
  }

  _copyArray(inputarr) {
    let newArr = []
    inputarr.forEach(element => {
      let item = {
        ...element
      }
      newArr.push(item)
    })
    return newArr

    // return inputarr.concat([])
  }

  render() {
    return (
      <View style={styles.container}>
        <ScrollableTabView
          style={{ width: screenWidth }}
          tabBarBackgroundColor="#fff"
          tabBarActiveTextColor="#F63300"
          tabBarInactiveTextColor="#4a4a4a"
          tabBarTextStyle={{ fontSize: 14, top: 5 }}
          tabBarUnderlineStyle={{ backgroundColor: '#F63300', height: 2 }}
        >
          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="身高"
            pageStyle="shenggao"
          />
          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="体重"
            pageStyle="tizhong"
          />
          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="体温"
            pageStyle="tiwen"
          />
          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="心率"
            pageStyle="xinlv"
          />

          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="脉搏"
            pageStyle="maibo"
          />
          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="呼吸"
            pageStyle="huxi"
          />
          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="大便"
            pageStyle="dabian"
          />
          <TabelePage1
            patientList={this._copyArray(this.state.patientList)}
            tabLabel="血压"
            pageStyle="xueya"
          />
        </ScrollableTabView>
      </View>
    )
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: theme_app.bg_color
  }
})

function select(store) {
  return { user_info: store.userInfo.user_info }
}

export default connect(select)(SignsBatch)
